/**
 * 项目名：五位一体化工安全信息平台
 * 日期：    2019-11-25 11:05:10
 * Copyright (c) 2015- joysuch-版权所有
 */

package com.joysuch.wwyt.core.repository;

import com.joysuch.wwyt.core.entity.BaseTypeGroup;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * BaseTypeGroupDao
 */
public interface BaseTypeGroupDao extends JpaRepository<BaseTypeGroup, Long> {
    public Page<BaseTypeGroup> findAll(Specification<BaseTypeGroup> spec, Pageable pageable);

    public BaseTypeGroup save(BaseTypeGroup bean);

    public void delete(BaseTypeGroup bean);

    @Query(value = "select * from wwyt_base_type_group  where code =?1 and delete_flag = '0' and (state = 1 or state is null)", nativeQuery = true)
    public BaseTypeGroup findByCode(String code);

    @Query(value = "select * from wwyt_base_type_group  where name =?1 and delete_flag = '0' and (state = 1 or state is null)", nativeQuery = true)
    public BaseTypeGroup findByName(String name);

    @Query(value = "select * from wwyt_base_type_group where code =?1 and delete_flag = '0'and (state = 1 or state is null)", nativeQuery = true)
    List<BaseTypeGroup> getListByCode(String abbrev);

    @Query(value = "select * from wwyt_base_type_group where delete_flag = '0' and (state =?1 or state is null)", nativeQuery = true)
    List<BaseTypeGroup> findByState(int i);

    @Query(value = "select * from wwyt_base_type_group where delete_flag = '0' and (state =1 or state is null)", nativeQuery = true)
    List<BaseTypeGroup> findAll();

    @Query(value = "select count(*) from wwyt_base_type_group where name =?1 and delete_flag = '0' and (state =1 or state is null)", nativeQuery = true)
    int countByName(String name);
}
